function formSub(){
	var formList = document.querySelector(".form_list");
	var input = formList.querySelectorAll("input");
	var btnSubmit = document.querySelector(".sub");
	
	//正则
	var regChinese = /^[\u4e00-\u9fa5]+$/;
	var regMobile = /^1[34578]\d{9}$/;
	
	//对应每个input的布尔值
	var submitAble1 = false;
	var submitAble2 = false;
	
	var cookie ="姓名=王呵呵; 手机=13241223453";

	//数据填充
	function getCookie() {
		var arr = cookie.split("; ");
		for (var i = 0; i < arr.length; i++) {
			var arr2 = arr[i].split("=");
			if (input[i].type == "text" || input[i].type == "email" || input[i].type ==
				"mobile") {
				input[i].value = arr2[1];
			}
		}
	}
	
	
	//循环校验
	function eachCheck() {
		for (var i = 0; i < input.length - 1; i++) {
			//存储每一个input
			var curInput = input[i];
			//获取type更改为获取name
			var type = curInput.getAttribute("name");
			//获取value
			var val = curInput.value;
			//通过name判断是哪个input，然后再判断是否为空、是否匹配正则规则
			switch (type) {
				case "name":
					if (val === "" || !regChinese.test(val)) {
						curInput.style.borderColor = "#f16d2a";
						submitAble1 = false;
//						alert("信息有误");
					} else {
						curInput.style.borderColor = "#ccc";
						submitAble1 = true;
					}
					break;
				case "tel":
					if (val === "" || !regMobile.test(val)) {
						curInput.style.borderColor = "#f16d2a";
						submitAble2 = false;
//						alert("信息有误");
					} else {
						curInput.style.borderColor = "#ccc";
						submitAble2 = true;
					}
					break;
			}
		}
	}
	
	//提交表单
	function submitFn() {
		//键盘抬起时
		for (var i = 0; i < input.length; i++) {
			input[i].onkeyup = function() {
				eachCheck();
			}
		}
		//点击下一步按钮时
		btnSubmit.onclick = function() {
			eachCheck();
			if (submitAble1 && submitAble2 ) {
				alert("提交成功");
			}else{
				alert("信息有误");
			}
		}
	}
	
	//初始化
	function init() {
		getCookie();
		submitFn();
	}
	init();
	
	$(".close").on("click",function(){
		$(".info").hide();
	})
}
formSub();
